package com.nl.lib_core.view

import android.graphics.Canvas
import android.graphics.Paint
import android.text.style.LineBackgroundSpan

/** 作者: wangfei 创建时间: 2021/9/16 包名: com.nl.lib_core.view 类名: CustomUnderlineSpan */
class CustomUnderlineSpan(underlineColor: Int) : LineBackgroundSpan {

  var mPaint =
      Paint().apply {
        color = underlineColor
        this.strokeWidth = 1F
        style = Paint.Style.FILL_AND_STROKE
      }

  override fun drawBackground(
      canvas: Canvas,
      paint: Paint,
      left: Int,
      right: Int,
      top: Int,
      baseline: Int,
      bottom: Int,
      text: CharSequence,
      start: Int,
      end: Int,
      lineNumber: Int
  ) {
    var length = mPaint.measureText(text.subSequence(start, end).toString())
    canvas.drawLine(0f, baseline + 20f, length, baseline + 20f, this.mPaint)
  }
}
